// 云函数入口文件
const cloud = require("wx-server-sdk");
cloud.init();

// 云函数入口函数
exports.main = async (event, context) => {
  try {
    const { cloudID } = event;
    if (!cloudID) {
      return {
        success: false,
        msg: "缺少 cloudID",
      };
    }
    // 调用微信云开发 openapi 获取手机号
    const res = await cloud.openapi.cloudbase.getPhoneNumber({
      cloudID: cloudID,
    });
    return {
      success: true,
      phoneNumber: res.phoneInfo.phoneNumber,
      purePhoneNumber: res.phoneInfo.purePhoneNumber,
      countryCode: res.phoneInfo.countryCode,
    };
  } catch (e) {
    return {
      success: false,
      msg: e.message,
    };
  }
};
